package com.siae.controller;


import com.siae.pojo.UserItem;
import com.siae.pojo.vo.Result;
import com.siae.service.UserItemService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/userItem")
@Tag(name = "UserItemController",description = "团队操作")
public class UserItemController {
    @Autowired
    private UserItemService userItemService;

    @GetMapping
    public Result<List<Map>> getAllItems(
            @RequestParam(value = "name",defaultValue = "") String name,
            @RequestParam(value = "userId",defaultValue = "0") Integer userId,
            @RequestParam(value = "itemId",defaultValue = "0") Integer itemId){
    	return userItemService.getAllItems(name, userId,itemId);
    }
    @GetMapping("/name")
    public Result<UserItem> getUserItemByName(@RequestParam(name = "name", defaultValue = "") String name){
    	return userItemService.getUserItemByName(name);
    }
    @GetMapping("/{id}")
    public Result<UserItem> getItemById(@PathVariable("id") Integer id){
    	return userItemService.getItemById(id);
    }
    @PostMapping
    public Result addItem(@RequestBody Map dateMap){
    	return userItemService.addItem(dateMap);
    }
    @PutMapping
    public Result updateItem(@RequestBody Map dateMap){
    	return userItemService.updateItem(dateMap);
    }
    @DeleteMapping("/{id}")
    public Result deleteItem(@PathVariable("id") Integer id){
    	return userItemService.deleteItem(id);
    }
}
